﻿'***************************************************************************\
' Module Name: AudioEndpointListControl.vb
' Project: SetDefaultAudioEndpoint http://sdae.codeplex.com/
' Copyright 2011 by jeff
' 
' This source is subject to the GNU General Public License version 2 (GPLv2).
' See http://www.gnu.org/licenses/gpl-2.0.html.
' All other rights reserved.
' 
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
'***************************************************************************/

Imports System.Windows.Automation

Namespace Windows7

  Class AudioEndpointListControl

    Private ReadOnly myAudioEndpointListControl As AutomationElement

    Public Sub New(ByVal control As AutomationElement)
      If (control Is Nothing) Then
        Throw New ArgumentNullException("control")
      End If

      Me.myAudioEndpointListControl = control
    End Sub

    'Private Function AudioDevice(ByVal name As String) As AutomationElement
    '  'find device name in found list
    '  Dim result As AutomationElement = Me.AudioDeviceList.FindFirstInChildrenByName(name)

    '  Return result
    'End Function

    'Private Function AudioDeviceListText() As String
    '  Dim builder As New System.Text.StringBuilder

    '  builder.AppendLine()
    '  builder.AppendLine()

    '  For Each item As String In Me.AudioDeviceNames
    '    builder.Append("  ")
    '    builder.AppendLine(item)
    '  Next

    '  Return builder.ToString
    'End Function

    'Private Function AudioDeviceNames() As IEnumerable(Of String)
    '  Dim result As New List(Of String)

    '  For Each item As AutomationElement In Me.AudioDevices
    '    result.Add(item.Current.Name)
    '  Next

    '  Return result
    'End Function

    Private Function AudioEndpoints() As AutomationElementCollection
      Return Me.myAudioEndpointListControl.FindAll(TreeScope.Children, Condition.TrueCondition)
    End Function

     Public ReadOnly Property Endpoints() As IAudioEndpointList
      Get
        Dim result As New AudioEndpointList

        For Each item As AutomationElement In Me.AudioEndpoints
          Dim endpoint As New AudioEndpointListItemControl(item)
          result.Add(endpoint)
        Next

        Return result
      End Get
    End Property
  End Class
End Namespace